<template>
    <ul>
        <city-header></city-header>
        <city-search
            :cities="cities"
        >
        </city-search>
        <city-list 
            :hot-cities="hotCities" 
            :cities="cities"
            :letter="letter"
        >
        </city-list>
        <city-alphabet 
            :cities="cities"
            @change="handleLetterChange"
        >
        </city-alphabet>
    </ul>
</template>
<script>
import axios from 'axios'
import CityHeader from '@/components/CityHeader'
import CitySearch from '@/components/CitySearch'
import CityList from '@/components/CityList'
import CityAlphabet from '@/components/CityAlphabet'

export default {
    name:'City',
    components:{
        CityHeader,
        CitySearch,
        CityList,
        CityAlphabet
    },
    data(){
        return {
            hotCities:[],
            cities:{},
            letter:'A'
        }
    },
    mounted(){
        this.getCityInfo();
    },
    methods:{
        getCityInfo(){
            axios.get('/api/city.json')
                .then(this.handleGetCitySucc)
        },
        handleGetCitySucc(res){
            const data = res.data
            if(data.ret && data.data){
                this.hotCities = data.data.hotCities
                this.cities = data.data.cities
            }
        },
        handleLetterChange(letter){
            this.letter = letter;
        }

    }


}
</script>
<style lang="stylus" scoped>

</style>